<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-row>
        <el-col :span="6">
          <el-form-item label="用户ID" prop="userId">
            <el-input
              v-model="queryParams.userId"
              placeholder="请输入用户ID"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
<!--        <el-col :span="6">
          <el-form-item label="代理ID" prop="agencyId">
            <el-input
              v-model="queryParams.agencyId"
              placeholder="请输入代理ID"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>-->
        <el-col :span="12">
          <el-form-item style="float: right;padding-right: 250px">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>


    <el-table v-loading="loading" :data="listList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户id" align="center" prop="userId"/>
      <el-table-column label="用户昵称" align="center" prop="userName"/>
      <el-table-column label="进入时间" align="center" prop="joinTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.joinTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="进入原因" align="center" prop="joinReason"/>
      <el-table-column label="所属APP" align="center" prop="appName"/>
      <el-table-column label="代理id" align="center" prop="agencyId"/>
      <el-table-column label="代理名称" align="center" prop="agencyName"/>
      <el-table-column label="openid" align="center" prop="openid"/>
<!--      <el-table-column label="unionId" align="center" prop="unionId"/>-->
<!--      <el-table-column label="uuid" align="center" prop="uuid"/>-->
      <el-table-column label="wifi" align="center" prop="wifi"/>
      <el-table-column label="机型" align="center" prop="model"/>
      <el-table-column label="删除时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改黑名单对话框 -->
  </div>
</template>

<script>
import { listList2 } from '@/api/opearte/blacklist'

export default {
  name: 'List2',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 黑名单表格数据
      listList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        userName: null,
        joinTime: null,
        joinReason: null,
        agencyId: null,
        agencyName: null,
        openid: null,
        unionId: null,
        uuid: null,
        wifi: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询黑名单列表 */
    getList() {
      this.loading = true
      listList2(this.queryParams).then(response => {
        this.listList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        userName: null,
        joinTime: null,
        joinReason: null,
        agencyId: null,
        agencyName: null,
        openid: null,
        unionId: null,
        uuid: null,
        wifi: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        delFlag: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getList(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改黑名单'
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除黑名单编号为"' + ids + '"的数据项？').then(function() {
        return delList(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    }

  }
}
</script>
